import java.util.Stack;

class Solution {
    public static String removeDuplicates(String s) {
        Stack<Character> stack = new Stack<>();
        StringBuilder str = new StringBuilder();
        for (char c : s.toCharArray()){
            if(stack.isEmpty()){
                stack.push(c);
                continue;
            }
            if(stack.peek() != c){
                stack.push(c);
            }else {
                stack.pop();
                continue;
            }
        }
        for (char c : stack){
            str.append(c);
        }
        return str.toString();
    }

    public static void main(String[] args) {
        String s = "abbaca";
        System.out.println(removeDuplicates(s));
    }
}